<?
include_once("../functions/functions.php");

//FUNCTION DECLARATIONS
function GetVisitDetails1($client_id)
{
	$queryVisitDate = "SELECT * FROM er_page2
					   WHERE client_id='$client_id'
					   ORDER BY visit_id";

	$resultVisit = r_db($queryVisitDate);
	return $resultVisit;
}



function getNoOfVisits1($client_id)
{
	$queryNoOfVisits = "SELECT client_id, COUNT(visit_id)
						FROM er_page2
						WHERE client_id = $client_id
						GROUP BY client_id";

	$resultNoOfVisits = r_db($queryNoOfVisits);
	$rowNoOfVisits = mysql_fetch_array($resultNoOfVisits);
	$noOfVisits = $rowNoOfVisits[1];
	return $noOfVisits;
}

/*
function getVisit_id($client_id)
{
	$queryVisit_id = "SELECT *
					  FROM er_visit
					  WHERE client_id = '$client_id'
					  AND visit_date LIKE '2008%'
					  ORDER BY visit_id";

	$resultVisit_id = r_db($queryVisit_id);
	return $resultVisit_id;
}
*/

function getVisit_id($client_id)
{
	$queryVisit_id = "SELECT *
					  FROM er_visit
					  WHERE client_id = '$client_id'
					  AND visit_date LIKE '2008%'
					  ORDER BY visit_id";

	$resultVisit_id = r_db($queryVisit_id);
	return $resultVisit_id;
}

function getIDtype($idtype)
{
	$query="select identification_type from er_Identification_Type where identification_no='".$idtype."'";
	$resultIDtype = r_db($query);
	$row=mysql_fetch_array($resultIDtype);
	return $row;
}

?>

<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<link rel="stylesheet" type="text/css" href="../print.css">
<script LANGUAGE="JavaScript">
<!--
function windowPrint() {
	window.print();
	setTimeout("window.close();",1500);
}
 -->
</script>
</head>
<body onload="windowPrint();">

<?
global $client_id;
if (!isset($client_id)) {
	$client_id = $_GET['ClientID'];
}
if ($client_id > NULL) {
	{
		$result = getVisitDetails1($client_id);
		$i = 0;
		$visit = array();

		while ($temp = mysql_fetch_array($result))
		{
			$visit[$i] = $temp;
			$i++;
		}

		$result1 = getVisit_id($client_id);
		$x = 0;
		$dates = array();

		while ($temp1 = mysql_fetch_array($result1))
		{
			$dates[$x] = $temp1;
			$x++;
		}

	}
}

if (isset($client_id))
{
	$query = "SELECT * FROM er_Client WHERE client_id ='$client_id'";
	$sql = r_db($query);
	$row = mysql_fetch_array($sql);
	$idtyperesult=getIDtype($row[10]);
	echo "<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">\n";
	echo "<tr><td colspan=\"4\"><h3>Client Details</h3></td></tr>\n";
	echo  "<tr>
		<td width=\"20%\"><b>Surname:</b></td>
		<td width=\"30%\">$row[2]&nbsp;</td>
		<td width=\"20%\"><b>Given Name:</b></td>
		<td width=\"30%\">".$row[3]."&nbsp;</td>
	</tr>\n";

	$DOB =  $row[4];
	$DbDOB=explode("-",$DOB);
	$dayDOB=$DbDOB[2];
	$monthDOB=$DbDOB[1];
	$yearDOB=$DbDOB[0];
	$DOB=$dayDOB."/".$monthDOB."/".$yearDOB;
	
	if ($row[6]=="f")
		$gender="Female";
	else
		$gender="Male";
	echo  "<tr>
		<td><b>Date of Birth:</b></td>
		<td>$DOB</td>
		<td><b>Gender:</b></td>
		<td>$gender&nbsp;</td>
	</tr>\n";

	echo "<tr>
		<td><b>ID Type:</b></td>
		<td>".$idtyperesult[0]. "&nbsp;</td>
		<td><b>ID Reference No:</b></td>
		<td>" . $row[1]."&nbsp;</td>
	</tr>\n";
	$otheridvalue = $row[8];
	if ($otheridvalue != null)
	{
		echo   "<tr><td>&nbsp;</td><td>&nbsp;</td><td><b>Other ID Type:</b></td><td>" . $row[8]."&nbsp;</td></tr>\n";
	}


	echo "</table>";
}

?>

	<Br />
<table id="visit" width="100%" cellpadding="2" cellspacing="0">
	<h3>Current Year Visit(s)</h3>
	<tr>
	<th>Page 2 Visit Details</th>
	<?
	foreach ($visit as $v => $value) {
		if ($v < 3) {
			echo "<th class=\"green\">Visit #". ($v+1) ."</th>";
		}
		elseif ($v < 4) {
			echo "<th class=\"orange\">Visit #". ($v+1) ."</th>";
		}
		else {
			echo "<th class=\"red\">Visit #". ($v+1) ."</th>";
		}
	}
	?>
	</tr>


	<tr>

	</tr>

	<tr><td valign="top">Date</td>
			<?
			foreach ($dates as $v2 => $value2) {
				$DbDOB=explode("-",$value2['visit_date']);
				@$dayDOB=$DbDOB[2];
				@$monthDOB=$DbDOB[1];
				$yearDOB=$DbDOB[0];
				$dobDate=$dayDOB."/".$monthDOB."/".$yearDOB;
				echo "<td>$dobDate</td>";
			}
			?>
	</tr>

	<tr>
	<th>Presenting Issues</th>
	</tr>

	<tr><td valign="top" width="20%">Presenting Issue 1</td>
		<?
			foreach ($visit as $v => $value) {
				echo "<td>".$value['pres_is_1']."</td>";
			}
		?>
	</tr>
	<tr><td valign="top">Presenting Issue 2</td>
		<?
			foreach ($visit as $v => $value) {
				echo "<td>".$value['pres_is_2']."</td>";
			}
		?>
	</tr>
	<tr><td valign="top">Presenting Issue 3</td>
		<?
			foreach ($visit as $v => $value) {
				echo "<td>".$value['pres_is_3']."</td>";
			}
		?>
	</tr>
	<tr><td valign="top">Presenting Issue 4</td>
		<?
			foreach ($visit as $v => $value) {
				echo "<td>".$value['pres_is_4']."</td>";
			}
		?>
	</tr>


	<tr>
		<th>Options Discussed</th>
	</tr>
	<tr><td valign="top">Options Discussed 1</td>
		<?
			foreach ($visit as $v => $value) {
				echo "<td>".$value['opt_1']."</td>";
			}
		?>
	</tr>
	<tr><td valign="top">Options Discussed 2</td>
		<?
			foreach ($visit as $v => $value) {
				echo "<td>".$value['opt_2']."</td>";
			}
		?>
	</tr>
	<tr><td valign="top">Options Discussed 3</td>
		<?
			foreach ($visit as $v => $value) {
				echo "<td>".$value['opt_3']."</td>";
			}
		?>
	</tr>
	<tr><td valign="top">Options Discussed 4</td>
		<?
			foreach ($visit as $v => $value) {
				echo "<td>".$value['opt_4']."</td>";
			}
		?>
	</tr>


	<tr>
		<th>Case Worker Details</th>
	</tr>
	<tr><td valign="top">Does this client have a caseworker?</td>
		<?
			foreach ($visit as $v => $value) {
				echo "<td>".$value['casew']."</td>";
			}
		?>
	</tr>
	<tr><td valign="top">Caseworker name:</td>
		<?
			foreach ($visit as $v => $value) {
				echo "<td>".$value['casew_name']."</td>";
			}
		?>
	</tr>
	<tr><td valign="top">Caseworkers Organisation</td>
		<?
			foreach ($visit as $v => $value) {
				echo "<td>".$value['casew_org']."</td>";
			}
		?>
	</tr>

		<tr>
			<th>Client Signature</th>
		</tr>
		<tr><td valign="top">Did the client provide a signature?</td>
			<?
				foreach ($visit as $v => $value) {
					echo "<td>".$value['client_sig']."</td>";
				}
			?>
		</tr>
		<tr><td valign="top">Time taken: (h:m)</td>
			<?
				foreach ($visit as $v => $value) {
					echo "<td>".$value['time_taken']."</td>";
				}
			?>
		</tr>
		<tr><td valign="top">Duty worker:</td>
			<?
				foreach ($visit as $v => $value) {
					echo "<td>".$value['duty_worker']."</td>";
				}
			?>
	</tr>
</table>
	<br />
	<br />
<script language="javascript">
	window.print();
</script>
</body>
</html>